<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <p>收到客户端发来的信息：<span id="data"></span></p>
  <div>user input: <input id="content" type="text"><button onclick="handleClick()">提交</button></div>
  <script src="/package/socket.io.js"></script>
  <script>
    var socket = io('http://child.cross.com:8080')
    socket.on('connect', function() {
      socket.on('message', function(msg) {
        document.getElementById('data').innerText = msg
      })
      socket.on('disconnect', function() {
        console.log('服务器已经关闭')
      })
    })
    function handleClick() {
      var data = document.getElementById('content').value
      socket.send(data)
      console.log(data)
    }
  </script>
</body>
</html>